#include <sys/types.h>         
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <signal.h>

#include "ipc_api.h"
#include <unistd.h>


typedef struct {
	int			running;
}shareMemClient_s;
static shareMemClient_s	shareMemClient = {1};
static shareMemClient_s	*pShareMemClient = &shareMemClient;

void signalRountine(int signNo)
{
	switch(signNo)
	{
		case SIGINT://ctrl+c
			pShareMemClient->running = 0;
			break;
		case SIGTERM://kill
			pShareMemClient->running = 0;
			break;
	}
}

#define TEST_LEN (1024)

int main(int argc,char *argv[])
{
	ipcRet_e	ret = ipcSuccess;
	ipcLog_s	log = {IPC_LOG_DEBUG,IPC_LOG_2_STDERR};
	int create	 = FALSE;
	ipcLockContext_s context ={getpid(),(char *)"client"};

	signal(SIGINT,signalRountine);
	signal(SIGTERM,signalRountine);
	
	ret = ipcLogInit(&log);
	ipcLogCheckRetThenReturn(ret);
	
	ret = ipcShareMemoryInit(create);
	ipcLogCheckRetThenReturn(ret);
	
	ret = ipcLockInit(create);
	ipcLogCheckRetThenReturn(ret);

	ret = ipcLock(&context);
	if(ipcSuccess == ret)
	{
		pIPCHandle->yourData[1] = 'c';
		ipcUnlock(&context);
	}
	
	while(pShareMemClient->running)
	{
		if(0 == pIPCHandle->yourData[0])
		{
			sleep(1);
		}
		else
		{	
			ipcLogDebug("client read yourData[0] %c \n",pIPCHandle->yourData[0]);
			break;
		}
	}

	ipcLockDeinit(create);
	ipcShareMemoryDeinit(create);
	ipcLogDeinit();

	return 0;
}

